<?php
/**
 * @author: liaofei<136327134@qq.com>
 * @day: 2021/6/11
 */

namespace App\Dao\system;
use App\Dao\BaseDao;
use App\Models\system\SystemLogModel;


/**
 * Class SystemLogDao
 * @package app\dao\system
 */
class SystemLogDao extends BaseDao
{
   
    public function setModel(){
        return SystemLogModel::class;
    }
    
   
     /**
      * 日志查询
      */
     public  function LogList($where){
         $name=$where['name'];
         
         $between=$where['between'];
         $type=$where['type'];
         $place = $this->models::when(!empty($where['type']), function ($query) use ($type) {
              
             return $query ->Where('type', $type);
            
         })->select(['admin_id','content','ip','id','created_at','title'])
         ->whereHas('admininfo', function($query) use($name){
         
             return $query->where('real_name', 'like', '%' . $name . '%');})
         
         ->with(['admininfo' => function($query) use ($name) {  //admininfo对应上面systemadmin模型中定义的userid方法名  闭包内是子查询
             return $query ->select(['account','real_name','id']);
         }])->when(!empty($where['create_time']), function ($query) use ($between) {
         
             return $query->whereBetween('created_at',$between);
         })
         ->orderBy('id','desc')
         ->paginate($where['limit']);
             $res = $this->formatData($place);
             return $res;
     }

  
   
}